{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "import time\n",
    "import torch\n",
    "import numpy as np\n",
    "from train_eval import train, init_network\n",
    "from importlib import import_module\n",
    "import argparse\n",
    "from utils import build_dataset, build_iterator, get_time_dif\n",
    "\n",
    "# parser = argparse.ArgumentParser(description='Chinese Text Classification')\n",
    "# args = parser.parse_args()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "dataset = 'THUCNews'  # 数据集\n",
    "\n",
    "model_name = 'bert' # bert\n",
    "x = import_module('models.' + model_name)\n",
    "config = x.Config(dataset)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "180000it [00:37, 4825.67it/s]\n",
      "10000it [00:02, 4330.01it/s]\n",
      "10000it [00:02, 4607.11it/s]\n"
     ]
    }
   ],
   "source": [
    "train_data, dev_data, test_data = build_dataset(config)\n",
    "train_iter = build_iterator(train_data, config)\n",
    "dev_iter = build_iterator(dev_data, config)\n",
    "test_iter = build_iterator(test_data, config)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(tensor([[ 101,  704, 1290,  ...,    0,    0,    0],\n",
      "        [ 101,  697, 1921,  ...,    0,    0,    0],\n",
      "        [ 101,  691,  126,  ...,    0,    0,    0],\n",
      "        ...,\n",
      "        [ 101,  783, 7183,  ...,    0,    0,    0],\n",
      "        [ 101, 2458, 4669,  ...,    0,    0,    0],\n",
      "        [ 101, 3136, 5509,  ...,    0,    0,    0]], device='cuda:0'), tensor([19, 23, 21, 25, 22, 21, 17, 22, 16, 12, 21, 23, 22, 16,  8, 17, 20, 24,\n",
      "         8, 10, 18, 16, 24, 21, 18, 15, 11, 21, 19, 19, 22, 22, 17, 23, 24, 17,\n",
      "        13, 18, 23, 19, 23, 21, 23, 21, 20, 14, 18, 16, 18, 24, 16, 23, 21, 17,\n",
      "        16, 13, 23, 20, 21, 21, 13, 23, 18, 15, 25, 17, 21, 23, 23, 14, 20, 20,\n",
      "        18, 17, 23, 15, 23, 21, 20, 15, 22, 21, 22, 20, 20, 15, 13, 21, 22, 15,\n",
      "        21, 21, 23, 15, 23, 19, 17, 18, 14, 21, 14, 16, 21, 12, 17, 23, 15, 22,\n",
      "        16, 16, 16, 18, 22, 16, 25, 17, 19, 18, 15, 18, 13, 22, 21, 14, 22, 17,\n",
      "        16, 22], device='cuda:0'), tensor([[1, 1, 1,  ..., 0, 0, 0],\n",
      "        [1, 1, 1,  ..., 0, 0, 0],\n",
      "        [1, 1, 1,  ..., 0, 0, 0],\n",
      "        ...,\n",
      "        [1, 1, 1,  ..., 0, 0, 0],\n",
      "        [1, 1, 1,  ..., 0, 0, 0],\n",
      "        [1, 1, 1,  ..., 0, 0, 0]], device='cuda:0')) tensor([3, 4, 1, 7, 5, 5, 9, 1, 8, 4, 3, 7, 5, 2, 1, 8, 1, 1, 8, 4, 4, 6, 7, 1,\n",
      "        9, 4, 2, 9, 4, 2, 2, 9, 8, 9, 1, 3, 9, 5, 9, 6, 7, 2, 9, 5, 9, 4, 5, 6,\n",
      "        8, 1, 2, 1, 4, 0, 5, 4, 9, 6, 5, 5, 2, 4, 5, 5, 7, 8, 6, 7, 7, 2, 9, 0,\n",
      "        4, 6, 7, 2, 9, 7, 9, 0, 2, 9, 9, 4, 9, 0, 0, 4, 1, 2, 5, 5, 7, 0, 5, 9,\n",
      "        5, 3, 4, 6, 8, 3, 5, 9, 3, 9, 4, 9, 5, 4, 6, 2, 3, 6, 7, 4, 6, 2, 2, 2,\n",
      "        0, 1, 6, 4, 4, 2, 2, 3], device='cuda:0')\n"
     ]
    }
   ],
   "source": [
    "for i, (trains, labels) in enumerate(train_iter):\n",
    "    print(trains,labels)\n",
    "    break"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
